package com.easthome.process.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.easthome.common.result.Result;
import com.easthome.model.process.ProcessType;
import com.easthome.process.service.ProcessTypeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @description:
 * @author: 朱敦宇
 * @time: 2023/11/15 12:23
 */
@Api(tags = "审批类型")
@RestController
@RequestMapping("/admin/process/processType")
public class ProcessTypeController {
   @Autowired
    private ProcessTypeService processTypeService;
    @PreAuthorize("hasAuthority('bnt.processType.list')")
   @ApiOperation("分页查找审批类型")
    @GetMapping("/{page}/{limit}")
    public Result getPageList(@PathVariable("page") Long page,@PathVariable("limit") Long limit){
       Page<ProcessType> typePage = new Page<ProcessType>();
       typePage.setSize(limit);
       typePage.setCurrent(page);
       processTypeService.page(typePage);
       return Result.ok(typePage);
   }

   @ApiOperation("通过Id获取一个类型信息")
    @GetMapping("/get/{id}")
   @PreAuthorize("hasAuthority('bnt.processType.list')")
    public Result findById(@PathVariable("id") Long id){
       ProcessType byId = processTypeService.getById(id);
       return Result.ok(byId);
   }
   @ApiOperation("添加")
    @PostMapping("/save")
   @PreAuthorize("hasAuthority('bnt.processType.add')")
    public Result saveOne(@RequestBody ProcessType processType){
        processTypeService.save(processType);
        return Result.ok();
   }
    @PreAuthorize("hasAuthority('bnt.processType.update')")
    @ApiOperation(value = "修改")
    @PutMapping("update")
    public Result updateById(@RequestBody ProcessType processType) {
        processTypeService.updateById(processType);
        return Result.ok();
    }

    @PreAuthorize("hasAuthority('bnt.processType.remove')")
    @ApiOperation(value = "删除")
    @DeleteMapping("remove/{id}")
    public Result remove(@PathVariable Long id) {
        processTypeService.removeById(id);
        return Result.ok();
    }
}
